<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="生成新数据">
</body>
<script>
    // 获取元素 注册事件
    let btn = document.querySelector('input');
    btn.onclick = function(){
        let num = Math.floor(Math.random() * 10)
        console.log(num);
        localStorage.setItem('num',num);
    }
    let obj = {
        name:'LIER',
        age:18,
        gender:'男'
    }
    // 先将对象转换成 JSON 类型的字符串 JSON.stringify
    // 然后再把数据存进本地储存中
    let objJson = JSON.stringify(obj);
    localStorage.setItem('a',objJson);
    // 先取出json数据 然后将数据转化成对象 json.parse()
    let lier = JSON.parse(localStorage.getItem('a'));
    console.log(lier);

</script>
</html>